package com.example.jqying.androiddemo.recyclerView.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.jqying.androiddemo.R;
import com.example.jqying.androiddemo.recyclerView.adapter.GridAdapter;

public class GridRecyclerActivity extends AppCompatActivity {

    private RecyclerView mRvGrid;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_grid_recycler);
        mRvGrid = (RecyclerView) findViewById(R.id.rv_grid);

        //选择网格管理器
        mRvGrid.setLayoutManager(new GridLayoutManager(GridRecyclerActivity.this,2)); //2 表示有2列

        mRvGrid.setAdapter(new GridAdapter(GridRecyclerActivity.this, new GridAdapter.OnitemClickListener() {
            @Override
            public void onClick(int pos) {
                Toast.makeText(GridRecyclerActivity.this,"Clicked:"+pos,Toast.LENGTH_SHORT).show();
            }
        }));
    }
}
